#include<bits/stdc++.h>
using namespace std;
#define int long long
//struct node{
//	int t, idx;
//}a[100005];

int a[100005];

signed main(){
	int n, m;
	cin>>n>>m;
	
	for(int i = 1;i <= n;i++){
		cin>>a[i];
	}
	
//	if(m == 1){
//		cout<<accumulate(a+1, a+n+1, 0);
//		return 0;
//	}
	if(m == 1){
		int ans = 0;
		for(int i = 1;i <= n;i++){
			ans += a[i];
		}
		cout<<ans;
		return 0;
	}
	
	sort(a+1, a+n+1, greater<int>());
//	for(int i = 1;i <= n;i++){
//		cout<<i<<" "<<a[i]<<endl;
//	}
	priority_queue<int, vector<int>, greater<int>> q;
	
	int mx_time = -1;
	for(int i = 1;i <= m;i++){
		q.push(a[i]);
		mx_time = max(mx_time, a[i]);
	}
	for(int i = m+1;i <= n;i++){
		int t = q.top();
		q.pop();
		q.push(t+a[i]);
		mx_time = max(mx_time, t+a[i]);
	}
	cout<<mx_time;
	return 0;
}
